﻿using System.Globalization;
using System.IO;
using System.Reflection;
using System.Xml;

namespace IniFileManager
{
	/// <summary>
	/// Class for storing information about "IniSchema.xsd"'s 
	/// structure, its embedded location within assembly and
	/// ini schema xml validation (reading) settings. 
	/// </summary>
	internal static class IniSchemaXsd
	{
		// Embedded location of "IniSchema.xsd":
		internal const string INI_SCHEMA_XSD_PATH = "IniFileManager.IniSchema.xsd";
		internal static readonly CultureInfo cultureInfo = CultureInfo.InvariantCulture;
		internal static readonly XmlReaderSettings validationSettings;

		// Element names within "IniSchema.xsd":
		internal const string ELEMENT_BOOL_ELEMENT = "boolElement";
		internal const string ELEMENT_SIGNED_ELEMENT = "signedElement";
		internal const string ELEMENT_UNSIGNED_ELEMENT = "unsignedElement";
		internal const string ELEMENT_FLOAT_ELEMENT = "floatElement";
		internal const string ELEMENT_STRING_ELEMENT = "stringElement";
		internal const string ELEMENT_ENUM_ELEMENT = "enumElement";
		internal const string ELEMENT_ENUMERATION = "enumeration";

		// Attribute names within "IniSchema.xsd":
		internal const string ATTRIBUTE_ELEMENT_DELIMITER = "elementDelimiter";
		internal const string ATTRIBUTE_NAME = "name";
		internal const string ATTRIBUTE_REQUIRED = "required";
		internal const string ATTRIBUTE_DEFAULT = "default";
		internal const string ATTRIBUTE_MIN = "min";
		internal const string ATTRIBUTE_MAX = "max";

		/// <summary>
		/// Prepares "validationSettings" for validation ini schemas in xml with "IniSchema.xsd".
		/// </summary>
		static IniSchemaXsd()
		{
			Assembly assembly = Assembly.GetExecutingAssembly();
			Stream IniSchemaXsdStream = assembly.GetManifestResourceStream( INI_SCHEMA_XSD_PATH );
			XmlReader iniSchemaXsdReader = XmlReader.Create( new StreamReader( IniSchemaXsdStream ) );

			validationSettings = new XmlReaderSettings();
			validationSettings.Schemas.Add( null, iniSchemaXsdReader );
			validationSettings.ValidationType = ValidationType.Schema;
		}

	}
}
